package com.libertyville.domain.orgmng;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.util.stream.Stream;

@Converter
public class TenantStatusConverter implements AttributeConverter<TenantStatus, String> {
    @Override
    public String convertToDatabaseColumn(TenantStatus orgTypeStatus) {
        return orgTypeStatus.getCode();
    }

    @Override
    public TenantStatus convertToEntityAttribute(String code) {
        return Stream.of(TenantStatus.values())
                .filter(it -> it.getCode().equals(code))
                .findFirst()
                .orElseThrow(IllegalArgumentException::new);
    }
}
